package com.efurniture.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.efurniture.domain.Administrator;

public class AdministratorDAO implements IAdministrator{

	private HibernateTemplate hibernateTemplate;
	
	public void setSessionFactory(SessionFactory sessionFactory)
	{
		this.hibernateTemplate = new HibernateTemplate(sessionFactory);
	}
	
//	private HibernateTemplate hibernateTemplate;
//
//    public void setHibernateTemplate(HibernateTemplate hibernateTemplate){
//        this.hibernateTemplate = hibernateTemplate;
//    }
//
//    public HibernateTemplate getHibernateTemplate(){
//        return hibernateTemplate;
//    }
	
	@Override
	public List<Administrator> get() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Administrator get(String value) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean insert(Administrator admin) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean update(Administrator admin) {
		// TODO Auto-generated method stub
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public boolean checkAccount(String user, String pass) {
		// TODO Auto-generated method stub
		List<Administrator> list = null;
		try {
			list = this.hibernateTemplate.find("from Administrator where account ='" + user + "' and password ='" + pass +"'");
			if(list.isEmpty()){
				return false;
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			//return false;
		}
		
		return true;
	}
	
}
